package zhihui.mobile.ui.myself;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.zgm.utils.UiUtils;
import com.zgm.utils.ui.UiTextHeader;

import zhihui.mobile.R;
import zhihui.mobile.manager.user.UserManager;
import zhihui.mobile.presenter.IPresenter;
import zhihui.mobile.presenter.myself.UpdateNamePresenter;
import zhihui.mobile.ui.BaseActivity;

/**
 * Created by 张公铭 on 2017/9/24 0024.
 */

public class UpdateNameActivity extends BaseActivity implements IUpdateNameContract.IUpdateNameView
{
    private IUpdateNameContract.IUpdateNamePresenter updateNamePresenter = new UpdateNamePresenter();

    private UiTextHeader header;
    private EditText ed_name;
    private ImageView iv_clean;

    @Override
    public void initView()
    {
        header = (UiTextHeader) findViewById(R.id.header_setting_update_name);
        header.setBackgroundColor("#4b85e4");
        header.setTitle("修改昵称");
        header.setTitleColor("#ffffff");
        header.setLeftBottonIcon(R.drawable.back);
        header.setLeftButtonOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                goBack(UpdateNameActivity.class);
            }
        });

        header.setRightText("确定");
        header.setRightTextColor("#ffffff");
        header.setRightTextListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //保存
                updateNamePresenter.saveUserName(ed_name.getText().toString());
            }
        });

        ed_name = (EditText) findViewById(R.id.ed_setting_update_name);
        ed_name.setText(UserManager.getInstance().getCurUser().getName());

        iv_clean = (ImageView) findViewById(R.id.iv_setting_update_name_clean);
        iv_clean.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                ed_name.setText("");
                UiUtils.editTextFocus(ed_name);
            }
        });
        UiUtils.editTextFocus(ed_name);
    }

    @Override
    protected int getLayoutResId()
    {
        return R.layout.setting_update_name_activity;
    }

    @Override
    protected IPresenter[] getPresenters()
    {
        return new IPresenter[]{ updateNamePresenter };
    }

    @Override
    protected void onInitPresenter()
    {
        updateNamePresenter.init(this, this);
    }
}
